package ru.vboxdc.domain;

import ru.vboxdc.iface.HostServerManager;

import java.util.*;

/**
 * User: lelon
 * Date: 08.02.2009
 * Time: 22:48:44
 */
public class HostServer implements Comparable {


    private HostServerManager manager;
    // Список виртуальных машин для этого хост-сервера
    private List<VirtualMachine> virtualMachineList = new ArrayList();


    private Integer id;
    private String host;
    private String user;
    private String password;
    private String name;
    private HostServerType serverType;

    @Override
    public String toString() {
        return name;
    }

    public HostServerManager getManager() {
        return manager;
    }

    public void setManager(HostServerManager manager) {
        this.manager = manager;
    }


    public void addVMachine(VirtualMachine virtualMachine) {
        virtualMachineList.add(virtualMachine);
        Collections.sort(virtualMachineList);
    }

    public void removeVirtualMachine(VirtualMachine virtualMachine) {
        virtualMachineList.remove(virtualMachine);
    }

    public List<VirtualMachine> getVirtualMachines() {
        return virtualMachineList;
    }

    public void refreshVirtualMachines()
    {
        virtualMachineList.addAll(manager.getVirtualMachines());
        Collections.sort(virtualMachineList);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public HostServerType getServerType() {
        return serverType;
    }

    public void setServerType(HostServerType serverType) {
        this.serverType = serverType;
    }


    @Override
    public int compareTo(Object o) {
        return name.compareTo(o.toString());
    }
}
